/***
This do-file plots the evolution of low-wage employment by citizenship
status (citizens at birth, naturalized citizens, non-citizens).
***/

*-------------------------------------------------------------------------------
* Set up
*-------------------------------------------------------------------------------

* Set $root 
project figstabs, root
if (r(buildrunning)==0) include "${root}/code/config_interactive.do"

* Set globals
project, uses("${root}/code/set_globals.do")
include "${root}/code/set_globals.do"
local category "Employment"

* Create required subfolders
cap mkdir "${root}/data/derived/Employment"
cap mkdir "${root}/results/Employment"

*-------------------------------------------------------------------------------
* Load and process data
*-------------------------------------------------------------------------------

* Load CPS by quartile and citizenship status data
project, uses("${root}/data/derived/CPS/CPS by wage quartile and citizenship.dta")
use "${root}/data/derived/CPS/CPS by wage quartile and citizenship.dta", clear

keep if quartile == 1

reshape wide norm_emp_cps , i(date) j(cit_status)

* Merge CPS by wage quartile 
project, uses("${root}/data/derived/CPS/CPS by wage quartile.dta")
merge 1:1 date quartile using "${root}/data/derived/CPS/CPS by wage quartile.dta", assert(2 3) keep(3) nogen

keep if inrange(date, mdy(1, 1, 2020), ${finaldate})

*-------------------------------------------------------------------------------
* Plot
*-------------------------------------------------------------------------------

tw ///
(connected norm_emp_cps1 date , sort color(oi1)) ///
(connected norm_emp_cps2 date , sort color(oi2) lpattern(dash)) ///
(connected norm_emp_cps3 date , sort color(oi5) lpattern(shortdash) lwidth(medium)) ///
(connected norm_emp_cps date , sort color(oi4)) ///
, ///
legend(on order(1 "Q1 Citizens at Birth" 2 "Q1 Naturalized Citizens" 3 "Q1 Non-citizens" 4 "Q1 Total") ring(1) pos(6) cols(4) symxsize(*0.5) size(small)) ///
ytitle("Employment Relative to January 2020 (%)") ///
	xtitle("",)  ///
	title(" ", size(vhuge)) ///
	ylabel(20 "+20%" 0 "0%" -20 "-20%" -40 "-40%" -60 "-60%", nogrid) ///
	xlabel(`=mdy(1,15,2020)' `""Jan" "2020""' `=mdy(3,15,2020)' "Mar" `=mdy(5,15,2020)' "May" ///
	`=mdy(7,15,2020)' "July" `=mdy(9,15,2020)' "Sep" `=mdy(11,15,2020)' "Nov" ///
	`=mdy(1,15,2021)' `""Jan" "2021""' `=mdy(3,15,2021)' "Mar" `=mdy(5,15,2021)' "May" ///
	`=mdy(7,15,2021)' "July" `=mdy(9,15,2021)' "Sep" `=mdy(11,15,2021)' "Nov") 	
oi_graph_export "${root}/results/Employment/Trends in Employment by Citizenship", type(${fig_type}) 
